<?php
/**
 * @property JobVersion $JobVersion
 * @property SessionComponent $Session
 */
class JobVersionsController extends AppController {

	var $name = 'JobVersions';
	var $helpers = array('Js');

  /**
   * INDEX
   */
	function index() {
		$this->JobVersion->recursive = 0;
		$this->set('jobVersions', $this->paginate());
	}

   /**
   * VIEW
   */
	function view($id = null) {
		if (!$id) {
			//$this->Session->setFlash(__('Invalid job version id.', true));
      $this->addFlashMsg('Invalid job version id passed to JobVersionsController::view().', $this->flashError);
			$this->redirect(array('action' => 'index'));
		}
		$this->set('jobVersion', $this->JobVersion->read(null, $id));
	}

  /**
   * ADD - Note:  I'm now using JobsController to handle the adding of JobVersions.  See it's 'form()'.
   */
	function add() {
    /*
    ////////////////////////////////////////
    /////// When saving new data ///////////
		if (!empty($this->data)) {
			$this->JobVersion->create();
			if ($this->JobVersion->save($this->data)) {
				$this->Session->setFlash(__('The job version has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The job version could not be saved. Please, try again.', true));
			}
		}
    ////////////////////////////////////////////////
    ////////// When accessing new add page /////////
		$jobs = $this->JobVersion->Job->find('list');
		$statuses = $this->JobVersion->Status->find('list');
		$authors = $this->JobVersion->Author->find('list');
		$jobTypes = $this->JobVersion->JobType->find('list');
		$this->set(compact('jobs', 'statuses', 'authors', 'jobTypes'));
    // Prepulate the Version number with the incremented count
    $this->data['JobVersion']['version_num'] = 1;
    */
	} /////////////// end add() ///////////////////////////////

  /**
   * EDIT - Note:  I'm now using JobsController to handle the editing of JobVersions.  See it's 'form()'.
   */
	function edit($id = null) {
    /*
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid job version', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->JobVersion->save($this->data)) {
				$this->Session->setFlash(__('The job version has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The job version could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->JobVersion->read(null, $id);
		}
		$jobs = $this->JobVersion->Job->find('list');
		$statuses = $this->JobVersion->Status->find('list');
		$authors = $this->JobVersion->Author->find('list');
		$jobTypes = $this->JobVersion->JobType->find('list');
		$this->set(compact('jobs', 'statuses', 'authors', 'jobTypes'));
    */
	} ////////////// end edit() ////////////////

  /**
   * DELETE
   */
	function delete($id, $job_id) {
    
    //debug("controller to delete version id: "); debug($id);  die();

		if (!$id) {
			//$this->Session->setFlash(__('Cannot delete: Invalid id for job version', true));
      $this->addFlashMsg('Cannot delete: Invalid id for job version.', $this->flashError);
			$this->redirect(array('controller'=>'jobs' ,'action'=>'view', $job_id));
		}
		if ($this->JobVersion->delete($id)) {
			//$this->Session->setFlash(__('Job version deleted.', true));
      $this->addFlashMsg('Job version deleted.', $this->flashSuccess );
			$this->redirect(array( 'controller'=>'jobs' ,'action'=>'view', $job_id));
		}
    
		//$this->Session->setFlash(__('Job version was not deleted', true));
    $this->addFlashMsg('Job Version was NOT deleted. There could be a database or id problem. Try again.', 
                                $this->flashError);
		$this->redirect(array( 'controller'=>'jobs' ,'action'=>'view', $job_id));
    
	}
} ////////////////////////// end class ///////////////////////////
